﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation;
using Micrhard.FMCG.Server.Models;
using Micrhard.FMCG.Server.Msg;

namespace Micrhard.FMCG.Server.Validator
{
    public class OrderWorkSheetModelValidator : AbstractValidator<OrderWorkSheetModel>
    {
        public OrderWorkSheetModelValidator()
        {
            RuleSet("Insert", () =>
            {
                RuleFor(u => u.Name).NotEmpty().WithMessage(OrderWorkSheetMsg.NeeName).When(r => r.OrderExecuteID == Guid.Empty);
                RuleFor(u => u.Name).Length(1, 50).WithMessage(OrderWorkSheetMsg.MaxNameLength).When(r => r.OrderExecuteID == Guid.Empty);

                RuleFor(u => u.ExecuteContent).NotEmpty().WithMessage(OrderWorkSheetMsg.NeedExecuteContent).When(r => r.OrderExecuteID == Guid.Empty);
                RuleFor(u => u.ExecuteContent).Length(1, 50).WithMessage(OrderWorkSheetMsg.MaxExecuteContentLength).When(r => r.OrderExecuteID == Guid.Empty);
            });

            RuleSet("Update", () =>
            {
                RuleFor(u => u.Name).NotEmpty().WithMessage(OrderWorkSheetMsg.NeeName);
                RuleFor(u => u.Name).Length(1, 50).WithMessage(OrderWorkSheetMsg.MaxNameLength);

                RuleFor(u => u.ExecuteContent).NotEmpty().WithMessage(OrderWorkSheetMsg.NeedExecuteContent);
                RuleFor(u => u.ExecuteContent).Length(1, 50).WithMessage(OrderWorkSheetMsg.MaxExecuteContentLength);
            });
        }
    }
}
